//
//  HZAddressToolPanel.m
//  app
//
//  Created by 刘华舟 on 15/5/13.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZAddressToolPanel.h"
#import "HZOrderByerAddressModel.h"

static const NSInteger kPanelCellWidth = 480;
static const NSInteger kPanelCellHeight = 100;

@interface HZAddressToolPanel()

@property (strong, nonatomic) HZOrderByerAddressModel *model;

@property (strong, nonatomic) UILabel *titleLabel;

@property (strong, nonatomic) UIButton *defaultBtn;
@property (strong, nonatomic) UIButton *editBtn;
@property (strong, nonatomic) UIButton *deleteBtn;
@property (strong, nonatomic) UIButton *cancelBtn;

@end

@implementation HZAddressToolPanel

- (instancetype)initWithFrame:(CGRect)frame{
    frame = [[UIApplication sharedApplication] keyWindow].screen.bounds;
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = HZ_MALL_MASK_BACKGROUND_COLOR;
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureOnView)];
        [self addGestureRecognizer:tapGestureRecognizer];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_HALF ux:-kPanelCellWidth/2 fy:UB_1_4],
                                                                  [self.ubo uw:kPanelCellWidth uh:kPanelCellHeight])];
        self.titleLabel.text = @"    管理地址";
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.textColor = HZ_MALL_MAIN_THEME_ORANGE;
        self.titleLabel.font = JKAppGlobleFontContentText;
        self.titleLabel.backgroundColor = HZ_WHITE_COLOR;
        [self addSubview:self.titleLabel];
        
        //默认
        self.defaultBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.titleLabel.ufo fx:UB_LEFT fy:UB_BOTTOM py:1],
                                                                  [self.ubo uw:kPanelCellWidth uh:kPanelCellHeight])];
        [self.defaultBtn setTitle:@"    使用当前地址" forState:UIControlStateNormal];
        self.defaultBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.defaultBtn setTitleColor:HZ_MALL_TEXT_BLACK_COLOR forState:UIControlStateNormal];
        self.defaultBtn.backgroundColor = HZ_WHITE_COLOR;
        [self.defaultBtn.titleLabel setFont:JKAppGlobleFontContentText];
        self.defaultBtn.tag = AddrToolPanelBtnTagSetDefault;
        [self.defaultBtn addTarget:self action:@selector(toolBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.defaultBtn];
        
        //编辑
        self.editBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.defaultBtn.ufo fx:UB_LEFT fy:UB_BOTTOM py:1],
                                                                   [self.ubo uw:kPanelCellWidth uh:kPanelCellHeight])];
        [self.editBtn setTitle:@"    编辑地址" forState:UIControlStateNormal];
        self.editBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.editBtn setTitleColor:HZ_MALL_TEXT_BLACK_COLOR forState:UIControlStateNormal];
        self.editBtn.backgroundColor = HZ_WHITE_COLOR;
        [self.editBtn.titleLabel setFont:JKAppGlobleFontContentText];
        self.editBtn.tag = AddrToolPanelBtnTagEdit;
        [self.editBtn addTarget:self action:@selector(toolBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.editBtn];
        
        //删除
        self.deleteBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.editBtn.ufo fx:UB_LEFT fy:UB_BOTTOM py:1],
                                                                   [self.ubo uw:kPanelCellWidth uh:kPanelCellHeight])];
        [self.deleteBtn setTitle:@"    删除该地址" forState:UIControlStateNormal];
        self.deleteBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.deleteBtn setTitleColor:HZ_MALL_TEXT_BLACK_COLOR forState:UIControlStateNormal];
        self.deleteBtn.backgroundColor = HZ_WHITE_COLOR;
        [self.deleteBtn.titleLabel setFont:JKAppGlobleFontContentText];
        self.deleteBtn.tag = AddrToolPanelBtnTagDelete;
        [self.deleteBtn addTarget:self action:@selector(toolBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.deleteBtn];
        
        //删除
        self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.deleteBtn.ufo fx:UB_LEFT fy:UB_BOTTOM py:1],
                                                                  [self.ubo uw:kPanelCellWidth uh:kPanelCellHeight])];
        [self.cancelBtn setTitle:@"    取消" forState:UIControlStateNormal];
        self.cancelBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.cancelBtn setTitleColor:HZ_MALL_TEXT_BLACK_COLOR forState:UIControlStateNormal];
        self.cancelBtn.backgroundColor = HZ_WHITE_COLOR;
        [self.cancelBtn.titleLabel setFont:JKAppGlobleFontContentText];
        self.cancelBtn.tag = AddrToolPanelBtnTagDelete;
        [self.cancelBtn addTarget:self action:@selector(tapGestureOnView) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.cancelBtn];
        
    }
    return self;
}


//点击空白处
- (void)tapGestureOnView{
    [self removeFromSuperview];
}

//点击button
- (void)toolBtnOnClick:(id)btn{
    [self removeFromSuperview];
    UIButton *toolBtn = (UIButton *)btn;
    
    if (toolBtn.tag == AddrToolPanelBtnTagCancel) {
        return;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(addressToolPanelBtnOnClickWithModel: buttonTag:)]) {
        [self.delegate addressToolPanelBtnOnClickWithModel:self.model buttonTag:toolBtn.tag];
    }
    
}


- (void)showPanelWithModel:(HZOrderByerAddressModel *)model{
    
    self.model = model;
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
}

@end
